package com.xizi;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Singleton {

//    private volatile static Singleton uniqueInstance;
//
//    private Singleton() {
//    }
//
//    public  static Singleton getUniqueInstance() {
//       //先判断对象是否已经实例过，没有实例化过才进入加锁代码
//        if (uniqueInstance == null) {
//            //类对象加锁
//            synchronized (Singleton.class) {
//                if (uniqueInstance == null) {
//                    uniqueInstance = new Singleton();
//                }
//            }
//        }
//        return uniqueInstance;
//    }

    //同步代码块
    public class SynchronizedDemo {
        public void method() {
            synchronized (this) {
                System.out.println("synchronized 代码块");
            }
        }
    }

    //同步方法
    public class SynchronizedDemo2 {
        public synchronized void method() {
            System.out.println("synchronized 方法");
        }

    }

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
    }


}
